package com.ks.service;

import java.util.List;

import com.ks.dao.UserDao;
import com.ks.entity.User;
import com.ks.utils.Factory;

public class UserServiceImpl implements UserService {
	// 使用工厂模式创建Dao对象
	private UserDao userDao = (UserDao) Factory.getBean("userDao");

	public List<User> getAllUser() {
		return userDao.selectAllUser();
//		String sql = "select * from t_user ";
//		Connection conn = null;
//		PreparedStatement pstmt = null;
//		ResultSet rs = null;// 定义存放查询结果的结果集
//		User user = null;
//		try {
//			conn = JDBCUtil.getConnection();
//			pstmt = conn.prepareStatement(sql);
////			pstmt.setString(1, userId);
//			rs = pstmt.executeQuery();// 运行查询操作
//			if (rs.next()) {
//				user = new User();
//				user.setUsername(rs.getString("userId"));
//				user.setPassword(rs.getString("userName"));
//			}
//		} catch (SQLException e) {
//			e.printStackTrace();
//		} finally {
//			JDBCUtil.closeResultSet(rs);
//			JDBCUtil.closePreparedStatement(pstmt);
//
//		}
//		return null;
	}

	@Override
	public User getUserById(String username) {
		User user = userDao.selectOneUser(username);
		return user;
	}

	@Override
	public int insertOneUser(User user) {
		return userDao.insertOneUser(user);
	}

	@Override
	public int updateUser(User user) {
		return userDao.updateOneUser(user);
	}

	@Override
	public int deleteUser(String username) {
		return userDao.deleteOneUser(username);
	}

}
